package com.dries.portal.module.xxshop.controller;

import com.dries.common.api.CommonResult;
import com.dries.portal.module.xxshop.entity.Userorder;
import com.dries.portal.module.xxshop.service.IUserorderService;
import com.dries.portal.module.xxshop.vo.UserOrderInfoVo;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

/**
 * 用户订单
 *
 * @author dries
 * @email samphsanie@gmail.com
 * @date 2020-10-14 14:11:07
 */
@RestController
@RequestMapping("xxshop/userorder")
public class UserorderController {

    @Resource
    private IUserorderService userorderService;

    /**
     * 订单列表
     *      * 订单列表
     *      * 待付款 待核销 待评价
     */
    @GetMapping("/list")
    public CommonResult list(@RequestParam Map<String, Object> params){

        PageInfo<UserOrderInfoVo> userOrderInfoVoPageInfo = userorderService.orderList(params);

        return CommonResult.success(userOrderInfoVoPageInfo);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{orderid}")
    public CommonResult info(@PathVariable("orderid") Long orderid) {

		UserOrderInfoVo info = userorderService.getOrderInfoByOrderId(orderid);

        return CommonResult.success(info);
    }

    /**
     * 信息
     */
    @GetMapping("/infobyorderpid/{orderId}")
    public CommonResult infoByUserId(@PathVariable("orderId") Long orderId, @RequestParam("userId") Long userId) {

        UserOrderInfoVo info = userorderService.getOrderInfoByUserId(orderId , userId);

        return CommonResult.success(info);
    }

    /**
     * 保存
     */
    @PostMapping("/create")
    public CommonResult save(@RequestBody Userorder userorder){

		// userorderService.createOrder(userorder);

        return CommonResult.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public CommonResult update(@RequestBody Userorder userorder){
		userorderService.updateById(userorder);

        return CommonResult.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public CommonResult delete(@RequestBody Long[] orderids){
		userorderService.removeByIds(Arrays.asList(orderids));

        return CommonResult.success();
    }

}
